package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.xianbeiying.app.ckgl.MyApplication;
import com.xianbeiying.app.ckgl.R;
import com.xianbeiying.app.ckgl.bean.JINGXUNBean;
import com.xianbeiying.app.ckgl.bean.UrlBean;
import com.xianbeiying.app.ckgl.util.LogUtils;

/**
 * 首页数据适配
 */
public class HomeListdapter extends BaseAdapter{

private Context context;
private String [] title={"温室大棚西红柿最新种植技术","温室大棚丝瓜最新种植技术"};
private int [] imgId={R.mipmap.img_default1,R.mipmap.img_default2};
    private  JINGXUNBean jingxunBean;
public HomeListdapter(Context context,JINGXUNBean jingxunBean) {
        this.context = context;
    this.jingxunBean=jingxunBean;
        }

    @Override
    public int getCount() {
        return jingxunBean.getINFOS().size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_home_list, parent, false);
            holder = new ViewHolder();
            holder.tv_home_jx=(TextView) convertView.findViewById(R.id.tv_home_jx);
            holder.tv_home_content=(TextView) convertView.findViewById(R.id.tv_home_content);
            holder.iv_home_img=(ImageView) convertView.findViewById(R.id.iv_home_img);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_home_content.setText(jingxunBean.getINFOS().get(position).getTitle());
        LogUtils.e("url","http://"+ MyApplication.IP+UrlBean.IMAGES+jingxunBean.getINFOS().get(position).getImageurl());
        ImageLoader.getInstance().displayImage("http://"+ MyApplication.IP+UrlBean.IMAGES+jingxunBean.getINFOS().get(position).getImageurl(), holder.iv_home_img);
//        holder.iv_home_img.setImageResource(imgId[position]);
//        Glide.with(context)
//                .load("http://" + MyApplication.IP + UrlBean.IMAGES +jingxunBean.getINFOS().get(position).getImageurl())
//                .thumbnail(0.1f)
//                .into(holder.iv_home_img);
        return convertView;
    }

    private class ViewHolder{
        ImageView iv_home_img;
        TextView tv_home_jx;
        TextView tv_home_content;
    }
}
